package com.traceability.trace.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.traceability.common.annotation.Log;
import com.traceability.common.core.controller.BaseController;
import com.traceability.common.core.domain.AjaxResult;
import com.traceability.common.enums.BusinessType;
import com.traceability.trace.domain.Productionbase;
import com.traceability.trace.service.IProductionbaseService;
import com.traceability.common.utils.poi.ExcelUtil;
import com.traceability.common.core.page.TableDataInfo;

/**
 * 生产基地Controller
 * 
 * @author xulin
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/traceability-trace/productionbase")
public class ProductionbaseController extends BaseController
{
    @Autowired
    private IProductionbaseService productionbaseService;

    /**
     * 查询生产基地列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:productionbase:list')")
    @GetMapping("/list")
    public TableDataInfo list(Productionbase productionbase)
    {
        startPage();
        List<Productionbase> list = productionbaseService.selectProductionbaseList(productionbase);
        return getDataTable(list);
    }

    /**
     * 导出生产基地列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:productionbase:export')")
    @Log(title = "生产基地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Productionbase productionbase)
    {
        List<Productionbase> list = productionbaseService.selectProductionbaseList(productionbase);
        ExcelUtil<Productionbase> util = new ExcelUtil<Productionbase>(Productionbase.class);
        util.exportExcel(response, list, "生产基地数据");
    }

    /**
     * 获取生产基地详细信息
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:productionbase:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") Long baseId)
    {
        return success(productionbaseService.selectProductionbaseByBaseId(baseId));
    }

    /**
     * 新增生产基地
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:productionbase:add')")
    @Log(title = "生产基地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Productionbase productionbase)
    {
        return toAjax(productionbaseService.insertProductionbase(productionbase));
    }

    /**
     * 修改生产基地
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:productionbase:edit')")
    @Log(title = "生产基地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Productionbase productionbase)
    {
        return toAjax(productionbaseService.updateProductionbase(productionbase));
    }

    /**
     * 删除生产基地
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:productionbase:remove')")
    @Log(title = "生产基地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable Long[] baseIds)
    {
        return toAjax(productionbaseService.deleteProductionbaseByBaseIds(baseIds));
    }
}
